import os
import time
import unittest
from tools.BeautifulReport import BeautifulReport
from config import DIR_PATH
from common.configManager import local_config
from common.emailManager import sendmail

# #创建测试套件
suite = unittest.defaultTestLoader.discover(local_config.case_path(),"*")

#创建测试套件执行器
run = BeautifulReport(suite)

#定义测试报告的名字和路径
report_name = time.strftime("%Y%m%d")+"report"
log_path = os.path.join(DIR_PATH,local_config.report_path())
#执行测试套件
run.report(filename=report_name,description="iwebshop测试",log_path=log_path)

#发送邮件
time.sleep(4)
case_count = suite.countTestCases()  #获取套件中的用例数量
report_file = os.path.join(log_path,report_name+'.html')
sendmail.send_email(case_count,report_file)




